﻿using Com.Help.BLL.Utils;
using Com.Help.DBEntity;
using System.Collections.Generic;
using System.Linq;

namespace $NAMESPACE
{
    /// <summary>
    /// $TABLE_CHNAME
    /// </summary>
    public class $TABLEBLL
    {
        /// <summary>
        /// 查询所有信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="page">当前页数</param>
        /// <param name="rows">每页条数</param>
        /// <returns></returns>
        public static List<$TABLE_LOWER> GetList(int id,$IF_PARAMISNAME$int page, int rows)
        {
            List<$TABLE_LOWER> list = new List<$TABLE_LOWER>();
            using (helpdbEntities db = new helpdbEntities())
            {
                var data = db.$TABLE_LOWER.AsNoTracking().Where(d => $IF_D.STATE$);
                if (id > 0)
                {
                    data = data.Where(d => d.id == id);
                }$IF_FINDBYNAME$
                list = data.OrderByDescending(d => d.id).Skip((page - 1) * rows).Take(rows).ToList();
            }
            return list;
        }

        /// <summary>
        /// 新增/修改
        /// </summary>$SUMMARY_ALLCOLUMNS
        /// <returns></returns>
        public static int Save($PARAMCOLUMNS_TYPES)
        {
            int result = 0;
			$TABLE_LOWER d = new $TABLE_LOWER();
            if (id > 0)
            { //修改$SET_ALLCOLUMNS
                using (helpdbEntities db = new helpdbEntities())
                {
                    result = EFDBHelper.Update(d, new string[] { $PARAMCOLUMNS_STRING_R_FK }, true, db);
                }
            }
            else
            { //新增$SET_ALLCOLUMNS_R_FK
                using (helpdbEntities db = new helpdbEntities())
                {
                    d = db.$TABLE_LOWER.Add(d);
                    db.SaveChanges();
                    result = d.id;
                }
            }
            return result;
        }

        
    }
}
